package org.hzy.test1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class CallFunorPro {

	/**
	 * @param args
	 */
	static Configuration con = new Configuration().configure();
	static SessionFactory fac = con.buildSessionFactory();
	static Session sess = fac.getCurrentSession();

	static void ts1(String hql) {
		Transaction tran = sess.beginTransaction();
		Query query = sess.createQuery(hql);
		List list = query.list();
		System.out.println(list.size());
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
		tran.commit();
	}

	static void ts2() {
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			Connection con = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:orcl", "hzy", "accp");
			PreparedStatement pre = con
					.prepareStatement("select * from scott.dept");
			ResultSet rs = pre.executeQuery();

			ResultSetMetaData rsm = rs.getMetaData();

			System.out.println(rsm.getColumnType(1));

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static void main(String[] args) throws Exception, Exception {
		// TODO Auto-generated method stub

		// ts1("select my_xy(7369) from Emp e");

		// ts1("select my_yz() from Emp e");

/*		Transaction tran = sess.beginTransaction();
		//
		SQLQuery squery = sess
				.createSQLQuery("select get_sal(?) from scott.emp");
		squery.setParameter(0, "7369");

		List list = squery.list();
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}*/

		/*
		 * CallableStatement
		 * cal=sess.connection().prepareCall("{Call scott.selectdept(?,?)}");
		 * cal.setString(1, 10+""); cal.registerOutParameter(2,
		 * OracleTypes.CURSOR); cal.executeQuery(); ResultSet rs=(ResultSet)
		 * cal.getObject(2); while(rs.next()){
		 * System.out.println(rs.getString(1)+"  "+rs.getString(2)); }
		 */

		// tran.commit();

		ts2();

	}

}
